//
//  HomeViewController.m
//  TravelFollowYourHeart
//
//  Created by 鲁万玺 on 2017/12/8.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "HomeViewController.h"
#import "HomeCollectionViewCell.h"
#import "HomeCollectionReusableViewHeaderView.h"
#import "HomeCollectionReusableViewFooterView.h"

#import "SearchHomeViewController.h"
#import "HotViewController.h"
#import "ParticularsViewController.h"
#import "HomeRMTJModel.h"

#import "FilmCollectionViewCell.h"
#import "TravelCollectionViewCell.h"
#import "FilmCollectionModel.h"
#import "TravelCollectionModel.h"
#import "TravelsViewController.h"
#import "MyFilmCommentListViewController.h"
#import "TravelInforViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>

#import "HomeFooterCollectionReusableView.h"
#import "CityListViewController.h"
@interface HomeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,HomeCollectionReusableViewHeaderViewDelegate,UINavigationControllerDelegate, TravelCollectionCellDelegate>

@property (nonatomic, strong)UILabel *locationLabel;
@property (nonatomic, strong)UICollectionView *collectionView;
@property (nonatomic, weak)HomeCollectionReusableViewHeaderView *headView;

@property (nonatomic, assign)NSInteger page;

@property (nonatomic, strong)NSMutableArray *dataArr;
@property (nonatomic, assign)NSInteger rmtjId; /**< 1-7 */

@property (nonatomic, strong)NSMutableArray * filmDataArr;
@property (nonatomic, strong)NSMutableArray * travelDataArr;
@property (nonatomic, strong)FilmCollectionModel * filmModel;
@property (nonatomic, strong)TravelCollectionModel * travelModel;
@property (nonatomic, assign)int filmID;
@property (nonatomic, assign)int middleBlockTransfomTypeInt;
@property (nonatomic, assign)int likeType;//1、游记  2、美拍
@property (nonatomic, strong)TravelCollectionModelData * travelModelData;
@end

@implementation HomeViewController(Networking)

- (void)getRMTJ
{
    NSDictionary *dic = @{
                          @"sign":@(self.rmtjId),
                          @"row":@(10),
                          @"page":@(self.page)
                          };
    
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil]postNetworkRequestURLString:Url(@"/index/travels") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        [ws.collectionView.mj_footer endRefreshing];
        [ws.collectionView.mj_header endRefreshing];
        if (error)
        {
            
        }
        else
        {
            if ([obj[@"code"] integerValue] == 100000)
            {
                HomeRMTJModel *model = [HomeRMTJModel yy_modelWithDictionary:obj];
                if (ws.page == 1)
                {
                    [ws.dataArr removeAllObjects];
                }
                [ws.dataArr addObjectsFromArray:model.data];
                [ws.collectionView reloadData];
            }
        }
    }];
}

- (void)getTakeFilmData{
    NSDictionary *dic = @{
                          @"row":@(10),
                          @"page":@(self.page),
                          @"lng":@([LocationTool shareIntance].longitude),
                          @"lat":@([LocationTool shareIntance].latitude),
                          @"mid":[UserModel intance].member_id
                          };
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil]postNetworkRequestURLString:Url(@"/diary/video") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        [ws.collectionView.mj_footer endRefreshing];
        [ws.collectionView.mj_header endRefreshing];
        if (error)
        {
            
        }
        else
        {
            if ([obj[@"code"] integerValue] == 100000)
            {
                ws.filmModel = [FilmCollectionModel yy_modelWithDictionary:obj];
                if (ws.page == 1)
                {
                    [ws.filmDataArr removeAllObjects];
                }
                [ws.filmDataArr addObjectsFromArray:ws.filmModel.data];
                [ws.collectionView reloadData];
            }
        }
    }];
}

- (void)getTravelData{
    NSDictionary *dic = @{
                          @"row":@(10),
                          @"page":@(self.page),
                          @"lng":@([LocationTool shareIntance].longitude),
                          @"lat":@([LocationTool shareIntance].latitude)
                          };
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil]postNetworkRequestURLString:Url(@"/diary/diary") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        [ws.collectionView.mj_footer endRefreshing];
        [ws.collectionView.mj_header endRefreshing];
        if (error)
        {
            
        }
        else
        {
            if ([obj[@"code"] integerValue] == 100000)
            {
                ws.travelModel = [TravelCollectionModel yy_modelWithDictionary:obj];
                if (ws.page == 1)
                {
                    [ws.travelDataArr removeAllObjects];
                }
                [ws.travelDataArr addObjectsFromArray:ws.travelModel.data];
                [ws.collectionView reloadData];
            }
        }
    }];
}

- (void)transformLikesDataWithDid:(int)did{
    NSDictionary * dic = @{
                           @"mid":[UserModel intance].member_id,
                           @"token":[UserModel intance].token,
                           @"did":@(self.filmID),
                           @"type":@(self.likeType)
                           };
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/diary/toLike") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error)
        {
            [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
        }
        else
        {
            if ([obj[@"code"] integerValue] == 100000)
            {
                [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
            }
            else
            {
                [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
            }
        }
    }];
}

@end

@implementation HomeViewController

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.delegate = self;
    [self navUI];
//    self.collectionView.hidden = YES;
//    [self.view addSubview:self.tableView];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getLocation:) name:@"getLocation" object:nil];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
//    [self navUI];
    [self.collectionView.mj_header beginRefreshing];
}

- (NSMutableArray *)dataArr
{
    if (!_dataArr) {
        _dataArr = [NSMutableArray arrayWithCapacity:10];
    }
    return _dataArr;
}

- (NSMutableArray *)filmDataArr{
    if (!_filmDataArr) {
        _filmDataArr = [NSMutableArray arrayWithCapacity:10];
    }return _filmDataArr;
}

- (NSMutableArray *)travelDataArr{
    if (!_travelDataArr) {
        _travelDataArr = [NSMutableArray arrayWithCapacity:10];
    }return _travelDataArr;
}

- (NSInteger)rmtjId
{
    if (!_rmtjId)
    {
        _rmtjId = 1;
    }
    return _rmtjId;
}

#pragma mark - UI
- (void)navUI
{
    UIView *navVView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
    navVView.backgroundColor = [UIColor themeColor];
    [self.view addSubview:navVView];
    
    UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 44)];
    navView.backgroundColor = [UIColor themeColor];
    [self.view addSubview:navView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(leftClick:)];
    
    UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(15, 0, 60, 30)];
    leftView.centerY = navView.height/2;
    leftView.backgroundColor = [UIColor clearColor];
    [leftView addGestureRecognizer:tap];
    
    UIImageView *leftImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
    leftImage.image = [UIImage imageNamed:@"home_nav_location"];
    leftImage.centerY = leftView.height/2;
    leftImage.contentMode = UIViewContentModeScaleAspectFit;
    [leftView addSubview:leftImage];
    
    self.locationLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 40, 30)];
    self.locationLabel.font = DEF_FontSize_12;
    self.locationLabel.textAlignment = NSTextAlignmentCenter;
    self.locationLabel.textColor = [UIColor whiteColor];
    [leftView addSubview:self.locationLabel];
    
    UIImageView *rightImage = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.locationLabel.frame), 0, 10, 10)];
    rightImage.image = [UIImage imageNamed:@"icon_nav_locationslc"];
    rightImage.centerY = leftView.height/2;
    rightImage.contentMode = UIViewContentModeScaleAspectFit;
    [leftView addSubview:rightImage];
    [navView addSubview:leftView];
    
    UIButton *titleViewBtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(leftView.frame) +5, 0, 200/WIDTH_5S_SCALE, 25)];
    titleViewBtn.centerY = navView.height/2;
    titleViewBtn.backgroundColor = [UIColor whiteColor];
    titleViewBtn.titleLabel.font = DEF_FontSize_14;
    [titleViewBtn setTitle:@"请输入搜索关键字" forState:UIControlStateNormal];
    [titleViewBtn setImage:[UIImage imageNamed:@"home_nav_search"] forState:UIControlStateNormal];
    [titleViewBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [titleViewBtn addTarget:self action:@selector(searchClick:) forControlEvents:UIControlEventTouchUpInside];
    [titleViewBtn setCornerRadius:25.0/2];
    [navView addSubview:titleViewBtn];
    
    [self mainUI];
    
    WS(ws)
    [[LocationTool shareIntance]startLocation:^(NSString *city) {
       ws.locationLabel.text = city;
    }];
}

- (void)mainUI
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.minimumLineSpacing = 0.5;
    layout.minimumInteritemSpacing = 0.5;
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT -64 -49) collectionViewLayout:layout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([HomeCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([HomeCollectionViewCell class]) ];
    [self.collectionView registerClass:[FilmCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([FilmCollectionViewCell class])];
    [self.collectionView registerClass:[TravelCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([TravelCollectionViewCell class])];
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([HomeCollectionReusableViewHeaderView class]) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([HomeCollectionReusableViewHeaderView class])];
//    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([HomeCollectionReusableViewFooterView class]) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:NSStringFromClass([HomeCollectionReusableViewFooterView class])];
    [self.collectionView registerClass:([HomeFooterCollectionReusableView class]) forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:NSStringFromClass([HomeFooterCollectionReusableView class])];
    
    self.collectionView.backgroundColor = [UIColor lightGrayColor];
    self.collectionView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.collectionView];
    
    WS(ws)
    self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        ws.page = 1;
        if (ws.rmtjId<6)
        {
            [ws getRMTJ];
        }
        else if (ws.rmtjId<7)
        {
            [ws getTravelData];
        }else{
            [ws getTakeFilmData];
        }
    }];
    
    self.collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        ws.page ++;
        if (ws.rmtjId<6)
        {
            [ws getRMTJ];
        }
        else if (ws.rmtjId<7)
        {
            [ws getTravelData];
        }else{
            [ws getTakeFilmData];
        }
    }];
    [self.collectionView.mj_header beginRefreshing];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    BOOL isHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isHomePage animated:YES];
}

#pragma mark - Event
- (void)leftClick:(UIGestureRecognizer *)sender
{
    NSLog(@"点击定位");
    CityListViewController * cityList = [[CityListViewController alloc] init];
    cityList.chooseLocationCity = ^(NSString *cityStr){
        self.locationLabel.text = cityStr;
    };
    [self.navigationController pushViewController:cityList animated:YES];
}

#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.rmtjId<6) {
        return self.dataArr.count;
    }else if (self.rmtjId<7){
        return self.travelDataArr.count;
    }else{
        return self.filmDataArr.count;
    }
    
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.rmtjId<6)
    {
        HomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([HomeCollectionViewCell class]) forIndexPath:indexPath];
        cell.modelData = self.dataArr[indexPath.row];
        return cell;
    }else if (self.rmtjId<7){//小城故事
        TravelCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([TravelCollectionViewCell class]) forIndexPath:indexPath];
        cell.delegate = self;
        cell.modelData = self.travelDataArr[indexPath.row];
        __weak typeof (self)weakSelf = self;
        weakSelf.filmID = [cell.modelData.travelID intValue];
        cell.travelNoteCollectBlock = ^(UIButton * btn){
            NSLog(@"filmID:%i", weakSelf.filmID);
//            btn.selected = YES;
//            self.likeType = 1;
//            [self transformLikesDataWithDid:weakSelf.filmID];
        };
        return cell;
    }
    FilmCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FilmCollectionViewCell class]) forIndexPath:indexPath];
    cell.modelData = self.filmDataArr[indexPath.row];
    NSString * transformStr = cell.modelData.filmID;
    NSString * videoURLStr = cell.modelData.vic;
    WS(ws)
    cell.videoBlock = ^(){
        NSLog(@"添加按钮点击事件");
        NSURL *url = [NSURL URLWithString:videoURLStr];
        AVPlayer *avPlayer= [AVPlayer playerWithURL:url];
        if (@available(iOS 10.0, *)) {
            avPlayer.automaticallyWaitsToMinimizeStalling = NO;
        }
        AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
        playerViewController.player = avPlayer;
        [[UIViewController getCurrentVC] presentViewController:playerViewController animated:YES completion:nil];
        [playerViewController.player play];
    };
    cell.block = ^(){
        if ([UserModel isSaveLogin]) {
            MyFilmCommentListViewController * vc = [[MyFilmCommentListViewController alloc] init];
            vc.did =  [transformStr intValue];
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [AppHelper showLogin];
        }
    };
    cell.likeBlock = ^(){
        ws.filmID =  [transformStr intValue];
        self.likeType = 2;
        if ([UserModel isSaveLogin]) {
            [self transformLikesDataWithDid:ws.filmID];
        }else{
            [AppHelper showLogin];
        }
    };
    return cell;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if ([kind isEqualToString:UICollectionElementKindSectionHeader])
    {
        HomeCollectionReusableViewHeaderView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([HomeCollectionReusableViewHeaderView class]) forIndexPath:indexPath];
        headView.delegate = self;
        self.headView = headView;
        return headView;
    }
    else
    {
//        HomeCollectionReusableViewFooterView *footView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:NSStringFromClass([HomeCollectionReusableViewFooterView class]) forIndexPath:indexPath];
                
        HomeFooterCollectionReusableView * footView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:NSStringFromClass([HomeFooterCollectionReusableView class]) forIndexPath:indexPath];
        
        return footView;
    }
    return nil;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    return CGSizeMake(SCREEN_WIDTH, 520);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.rmtjId<6)
    {
        return  CGSizeMake(SCREEN_WIDTH/2 -0.5, 180/WIDTH_5S_SCALE);
    }else if (self.rmtjId<7){//热门推荐：游记
//        return CGSizeMake(SCREEN_WIDTH, 220/WIDTH_5S_SCALE);
        self.travelModelData = self.travelDataArr[indexPath.row];
        CGFloat labelBottomY = [self getLabelHeightWithText:self.travelModelData.title width:SCREEN_WIDTH - 20 font:14];
        if (SCREEN_HEIGHT < 569) {
            return CGSizeMake(SCREEN_WIDTH, (labelBottomY + 160)/WIDTH_5S_SCALE);
        }
        if (SCREEN_HEIGHT < 668) {
            return CGSizeMake(SCREEN_WIDTH, (labelBottomY + 180)/WIDTH_5S_SCALE);
        }
        else{
            return CGSizeMake(SCREEN_WIDTH, (labelBottomY + 200)/WIDTH_5S_SCALE);
        }
    }
    return CGSizeMake(SCREEN_WIDTH, 260/WIDTH_5S_SCALE);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    return CGSizeMake(SCREEN_WIDTH, 120);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([UserModel isSaveLogin]) {
        if (self.rmtjId < 6) {
#pragma mark - 跳转详情
            TravelInforViewController *vc = [[TravelInforViewController alloc]init];
            HomeCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([HomeCollectionViewCell class]) forIndexPath:indexPath];
            cell.modelData = self.dataArr[indexPath.row];
            vc.tid = [cell.modelData.dataId intValue];
            [self.navigationController pushViewController:vc animated:YES];
        }else if(self.rmtjId < 7){
            NSLog(@"点击游记");
            TravelsViewController * vc = [[TravelsViewController alloc] init];
            TravelCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([TravelCollectionViewCell class]) forIndexPath:indexPath];
            cell.modelData = self.travelDataArr[indexPath.row];
            vc.dID = [cell.modelData.travelID intValue];
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            NSLog(@"点击美拍");
            //        TravelCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([TravelCollectionViewCell class]) forIndexPath:indexPath];
            //        cell.modelData = self.travelDataArr[indexPath.row];
            
        }
    }else{
        [AppHelper showLogin];
    }
}

- (void)searchClick:(UIButton *)sender
{
    SearchHomeViewController *vc = [[SearchHomeViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - HomeCollectionReusableViewHeaderViewDelegate
//乡思乡游等点击事件
- (void)jieshaoClick:(NSInteger)index
{
    HotViewController *vc = [[HotViewController alloc]init];
    vc.isHiddenTitle = YES;
    if (index == 0) {
        vc.navigationItem.title = @"乡思乡游";
        self.middleBlockTransfomTypeInt = 1;
    }
    if (index == 1) {
        vc.navigationItem.title = @"绿色生活";
        self.middleBlockTransfomTypeInt = 2;
    }
    if (index == 2) {
        vc.navigationItem.title = @"郊外探险";
        self.middleBlockTransfomTypeInt = 3;
    }
    if (index == 3) {
        vc.navigationItem.title = @"寻找美味";
        self.middleBlockTransfomTypeInt = 4;
    }
    if (index == 4) {
        vc.navigationItem.title = @"旅途空间";
        self.middleBlockTransfomTypeInt = 5;
    }
    if (index == 5) {
        vc.navigationItem.title = @"小城故事";
        self.middleBlockTransfomTypeInt = 6;
    }
    vc.sign = [NSString stringWithFormat:@"%i", self.middleBlockTransfomTypeInt];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)moreClick
{
    HotViewController *vc = [[HotViewController alloc]init];
    vc.sign = @"1";
    vc.navigationItem.title = @"热门推荐";
    [self.navigationController pushViewController:vc animated:YES];
}

//——热门推荐——下按钮的点击事件
- (void)rmtjClick:(NSInteger)index
{
    if (index < 5) {
        if (index == 0) {
            self.rmtjId = 1;
        }else{
            self.rmtjId = index + 1;
        }
//        self.rmtjId = index;
        [self.collectionView.mj_header beginRefreshing];
    }else if(index < 6){
        self.rmtjId = index + 1;
        self.page = 1;
        [self getTravelData];
        [self.collectionView.mj_header beginRefreshing];
    }else{
        if ([UserModel isSaveLogin]) {
            //美拍
            self.rmtjId = index + 1;
            self.page = 1;
            [self getTakeFilmData];
            [self.collectionView.mj_header beginRefreshing];
        }else{
            [AppHelper showLogin];
        }        
    }
    
}
//自适应高度
- (CGFloat)getLabelHeightWithText:(NSString *)text width:(CGFloat)width font: (CGFloat)font{
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
    
    return rect.size.height;
}

//监听方法
- (void)getLocation:(NSNotification *)notification{
    NSDictionary * dic = notification.userInfo;
    self.locationLabel.text = dic[@"chooseLocation"];
    NSLog(@"选择地点：%@", self.locationLabel.text);
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"getLocation" object:nil];
}
@end
